<template>
	<view class="content">
		<text>请签名确认同意报价</text>
		<view class="imgs" v-if="img !== ''">
			<image class="img" :src="img" mode="widthFix"></image>
		</view>
		<button type="primary" @tap="doss">点击签名</button>
		<catSignature canvasId="canvas1"  @close="close" @save="save" :visible="isShow" />
	</view>
</template>

<script>
	import catSignature from "@/components/cat-signature.vue"
	export default {
		components: { catSignature },
		data() {
			return {
				img:'',
				isShow: false
			}
		},
		methods: {
			doss(){
				this.isShow = true
			},
			close(){
				this.isShow = false
			},
			save(val){
				this.isShow = false
				this.img = val
				let file = new this.$av.File('signature', {
					blob: {
						uri: val
					}
				})
				file.save().then(file => {
					this.img = file.attributes.url
					this.$emit('signed')
				}, error => {
					uni.showToast({
						title: '文件上传失败!',
						icon: 'none'
					})
				})
			},
			getImg() {
				return this.img
			}
		}
	}
</script>

<style>
	.content {
		margin-top: 20rpx;
		padding: 20rpx 40rpx;
		background-color: #FFFFFF;
	}
	.imgs{
		width: 100%; 
		height: 360rpx;
		display: flex;
		margin: 0 auto;
		flex-wrap: wrap;
	}
	.imgs img{
		width: 100%; 
		height: 100%;
	}
</style>
